package com.cbb.lease.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cbb.lease.mapper.CarConfigMapper;
import com.cbb.lease.pojo.entity.CarConfig;
import com.cbb.lease.service.CarConfigService;
import com.gsj.common.pojo.R;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @program: clms-eighth01
 * @description: 这是 一个汽车配置接口实现类
 * @author: 陈斌斌
 * @create: 2021-07-24 15:01
 **/
@Service
public class CarConfigServiceImpl implements CarConfigService {

    @Resource
    private CarConfigMapper carConfigMapper;

    @Override
    public R getAllConfig() {
        List<CarConfig> carConfigs = carConfigMapper.selectList(null);
        return R.ok().put("carConfigs",carConfigs);
    }

    @Override
    public R getAllConfigPage(Integer currentPage, Integer pageSize, CarConfig config) {
        QueryWrapper<CarConfig> queryWrapper = new QueryWrapper<>();
        Page<CarConfig> page = new Page<>(currentPage,pageSize);
        if (StringUtils.isNotEmpty(config.getConfigName())){queryWrapper.like("config_name",config.getConfigName());}
        Page<CarConfig> configPage = carConfigMapper.selectPage(page, queryWrapper);
        return R.ok().put("records",configPage.getRecords()).put("total",configPage.getTotal());
    }

    @Override
    public R delById(Integer id) {
        int i = carConfigMapper.deleteById(id);
        return R.ok();
    }

    @Override
    public R updateConfig(CarConfig config) {
        int i = carConfigMapper.updateById(config);
        return R.ok();
    }

    @Override
    public R addConfig(CarConfig config){
        int insert = carConfigMapper.insert(config);
        return R.ok();
    }

}
